package Database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;

public class DataBaseHelper extends SQLiteOpenHelper {
    public DataBaseHelper(Context context, String name, CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //Student table
        String table1 = "CREATE TABLE IF NOT EXISTS student(s_id TEXT NOT NULL, f_name TEXT, l_name TEXT, s_class TEXT, PRIMARY KEY(s_id));";
        //Class with id student table
        String table2 = "CREATE TABLE IF NOT EXISTS list_class(c_id TEXT NOT NULL, s_id TEXT NOT NULL, PRIMARY KEY(c_id,s_id));";
        //Class information
        String table3 = "CREATE TABLE IF NOT EXISTS class_name(class_id TEXT NOT NULL, class_name TEXT, t_id TEXT, periods INTEGER, PRIMARY KEY(class_id));";
        //Teacher account
        String table4 = "CREATE TABLE IF NOT EXISTS account(t_id INTEGER NOT NULL, password TEXT, name TEXT, log_time TEXT, PRIMARY KEY(t_id));";
        db.execSQL(table1);
        db.execSQL(table2);
        db.execSQL(table3);
        db.execSQL(table4);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int _oldVersion, int _newVersion) {
        db.execSQL("DROP TABLE IF EXISTS student");
        db.execSQL("DROP TABLE IF EXISTS account");
        db.execSQL("DROP TABLE IF EXISTS list_class");
        db.execSQL("DROP TABLE IF EXISTS class_name");
        onCreate(db);
    }


}
